﻿@model IEnumerable<LOMBARDISPICK.Model.LPWekaPrediction>          
@using LOMBARDISPICK.Web.Helpers;

@{
	ViewBag.Title = "Results";
	IEnumerable<LOMBARDISPICK.Model.LPWekaPrediction> runnerUp = Model.OrderByDescending(x => x.RunnerUpPrediction);
}


<script type="text/javascript">
$(function () {


		var WinnerData = [];
		@{
			int FlotIndex = 0;
			foreach (var item in Model)
			{
				@:WinnerData[@(FlotIndex)] = { label: "@(item.TeamAbbreviation) <img src='@(Url.Action("GetImage", "NFLTeams", new { id = @item.NFLTeamsID }))' style='height:30px; width:45px;' />", data: @(item.WinPrediction / (double)ViewData["winTotal"]) }
				FlotIndex++;
			};
		}

		var RunnerUpData = [];
		@{
			FlotIndex = 0;
			foreach (var item in Model)
			{
				@:RunnerUpData[@(FlotIndex)] = { label: "@(item.TeamAbbreviation) <img src='@(Url.Action("GetImage", "NFLTeams", new { id = @item.NFLTeamsID }))' style='height:30px; width:45px;' />", data: @(item.RunnerUpPrediction / (double)ViewData["runnerUpTotal"]) }
				FlotIndex++;
			};
		}

	$.plot($("#Winners"), WinnerData,
	{
			series: {
				pie: {
					show: true,
					radius: 1,
					tilt: 0.5,
					label: {
						show: true,
						radius: 1,
						formatter: function(label, series){
							return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
						},
						background: {
							opacity: 0.5,
							color: '#000'
						}
					},
					combine: {
						color: '#999',
						threshold: 0.1
					}
				}
			},
			legend: {
				show: false
			},
			grid: {
				hoverable: true,
				clickable: false
			}
	});

	$.plot($("#RunnerUps"), RunnerUpData,
	{
			series: {
				pie: {
					show: true,
					radius: 1,
					tilt: 0.5,
					label: {
						show: true,
						radius: 1,
						formatter: function(label, series){
							return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
						},
						background: {
							opacity: 0.5,
							color: '#000'
						}
					},
					combine: {
						color: '#999',
						threshold: 0.1
					}
				}
			},
			legend: {
				show: false
			},
			grid: {
				hoverable: true,
				clickable: false
			}
	});

});


function pieHover(event, pos, obj) 
{
	if (!obj)
                return;
	percent = parseFloat(obj.series.percent).toFixed(2);
	$("#hover").html('<span style="font-weight: bold; color: '+obj.series.color+'">'+obj.series.label+' ('+percent+'%)</span>');
}

function pieClick(event, pos, obj) 
{
	if (!obj)
                return;
	percent = parseFloat(obj.series.percent).toFixed(2);
	alert(''+obj.series.label+': '+percent+'%');
}
</script>


<div class="wrapper row1">
  <header id="header">
	<hgroup>
	  <h1>Calculated Prediction Results for @(Model.FirstOrDefault().YearToCalculate) Season</h1>
	</hgroup>
  </header>
</div>

<!-- content -->
<div class="wrapper row2">
	<div id="container">
	<!-- ################################################################################################ -->


<h2>Teams that are likely to make it to the SuperBowl and <strong>Win</strong></h2>
<table class="applySortFilterDataTable">
	<thead>
		<tr>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().YearToCalculate)
			</th>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().TeamName)
			</th>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().TeamAbbreviation)
			</th>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().PredictionResult)
			</th>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().WinPrediction)
			</th>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().RunnerUpPrediction)
			</th>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().NoPrediction)
			</th>
			<th>
				Team Logo
			</th>
		</tr>
	</thead>
	<tbody>
@foreach (var item in Model.Take(5).Where(x => x.WinPrediction >= .1)){
		<tr>
			<td>
				@(item.YearToCalculate)
			</td>
			<td>
				@item.TeamName
			</td>
			<td>
				@item.TeamAbbreviation
			</td>
			<td>
				@item.PredictionResult
			</td>
			<td>
				@item.WinPrediction
			</td>
			<td>
				@item.RunnerUpPrediction
			</td>
			<td>
				@item.NoPrediction
			</td>
			<td>
				<img src="@Url.Action("GetImage", "NFLTeams", new { id = @item.NFLTeamsID })" style="height:30px; width:45px;" />
			</td>
		</tr>
}
	</tbody>
</table>


<h2>Teams that will likely make it to the SuperBowl and <strong>Lose</strong></h2>
<table class="applySortFilterDataTable">
	<thead>
		<tr>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().YearToCalculate)
			</th>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().TeamName)
			</th>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().TeamAbbreviation)
			</th>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().PredictionResult)
			</th>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().WinPrediction)
			</th>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().RunnerUpPrediction)
			</th>
			<th>
				@Html.LabelFor(model => model.SingleOrDefault().NoPrediction)
			</th>
			<th>
				Team Logo
			</th>
		</tr>
	</thead>
	<tbody>
@foreach (var item in runnerUp.Take(5).Where(x => x.RunnerUpPrediction >= .1))
{
		<tr>
			<td>
				@(item.YearToCalculate)
			</td>
			<td>
				@item.TeamName
			</td>
			<td>
				@item.TeamAbbreviation
			</td>
			<td>
				@item.PredictionResult
			</td>
			<td>
				@item.WinPrediction
			</td>
			<td>
				@item.RunnerUpPrediction
			</td>
			<td>
				@item.NoPrediction
			</td>
			<td>
				<img src="@Url.Action("GetImage", "NFLTeams", new { id = @item.NFLTeamsID })" style="height:30px; width:45px;" />
			</td>
		</tr>
}
	</tbody>
</table>



	<h2>Winners Odds</h2>
    <div id="Winners" class="graph" style="height: 250px;"></div>

	<h2>Runner-Ups Odds</h2>
    <div id="RunnerUps" class="graph" style="height: 250px;"></div>




<br />
<br />
<h3>Summary Stats</h3>
<div>
@Html.Raw(Model.FirstOrDefault().strSummary)
</div>

<br />
<br />
<div>
<table>
	<tr>
		<th colspan="4">
			Confusion Matrix
		</th>
	</tr>
	<tr>
		<td>a</td><td>b</td><td>c</td><td>   <-- classified as</td>
	</tr>
@{int index = 0;
foreach (double[] row in Model.FirstOrDefault().cmMatrix)
  {
	@:<tr>
    foreach (double element in row)
    {
      @:<td>
	  @(element.ToString() + " ")
	  @:</td>
    }
	if(index == 0){
		@:<td>a = Winner</td>
	}
	if (index == 1)
	{
		@:<td>b = RunnerUp</td>
	}
	if (index == 2)
	{
		@:<td>c = No</td>
	}
	@:</tr>
	index++;
  }
}
</table>
</div>


		<!-- ################################################################################################ -->
	<div class="clear"></div>
	</div>
</div>